package com.jhf.skypac_pda.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.jhf.skypac_pda.R;
import com.jhf.skypac_pda.adapter.interfaces.BaseAdapter;
import com.jhf.skypac_pda.db.bean.DB_OperationRecord;

import java.util.List;

public class OrderDetailListAdapter extends BaseAdapter<OrderDetailListAdapter.OrderDetailListItemHolder> {
    private List<DB_OperationRecord> mList;
    private Context context;



    public OrderDetailListAdapter(Context mContext, @NonNull List<DB_OperationRecord> mList) {
        this.mList = mList;
        this.context = mContext;
    }

    @Override
    public OrderDetailListAdapter.OrderDetailListItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.orderdetail_list_item, parent, false);
        OrderDetailListAdapter.OrderDetailListItemHolder holder = new OrderDetailListAdapter.OrderDetailListItemHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull OrderDetailListAdapter.OrderDetailListItemHolder holder, final int position) {
        holder.material_code.setText(mList.get(position).getMaterialCode());
        holder.tv_stock_location_code.setText(mList.get(position).getStockLocationCode());


        holder.tv_scan_material_code_time.setText(mList.get(position).getScanPalletCodeTime());
        holder.tv_stock_location_code_time.setText(mList.get(position).getScanLocationCodeTime());

        String status = mList.get(position).getMaterialTankFeedingRecordStatusDesc();
        holder.order_status.setText(status);
        if (status.equals("未开始")) {
            holder.order_status.setTextColor(context.getResources().getColor(R.color.title_text_num));
        } else if (status.contains("完成")) {
            holder.order_status.setTextColor(context.getResources().getColor(R.color.status_feeding_done));
        } else if (status.equals("投料中") || status.equals("进行中")) {
            holder.order_status.setTextColor(context.getResources().getColor(R.color.status_feeding));
        } else {
            holder.order_status.setTextColor(context.getResources().getColor(R.color.title_text_quit));
        }

        /*holder.ll_order_detail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(null!=mViewClickListener){
                    mViewClickListener.post_detail(position);
                }
            }
        });*/

    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    static class OrderDetailListItemHolder extends RecyclerView.ViewHolder {
        TextView material_code;
        TextView order_status;
        TextView tv_scan_material_code_time;
        TextView tv_stock_location_code;
        TextView tv_stock_location_code_time;
        LinearLayout ll_order_detail;

        public OrderDetailListItemHolder(View itemView) {
            super(itemView);
            material_code=itemView.findViewById(R.id.material_code);
            tv_scan_material_code_time=itemView.findViewById(R.id.tv_scan_material_code_time);
            order_status=itemView.findViewById(R.id.order_status);
            tv_stock_location_code=itemView.findViewById(R.id.tv_stock_location_code);
            tv_stock_location_code_time=itemView.findViewById(R.id.tv_stock_location_code_time);
            ll_order_detail=itemView.findViewById(R.id.ll_order_detail);
        }
    }

    public interface ViewClickListener{
        void post_detail(int pos);
    }

    public void setViewClickListener(OrderDetailListAdapter.ViewClickListener mViewClickListener){
        this.mViewClickListener=mViewClickListener;

    }


    private OrderDetailListAdapter.ViewClickListener mViewClickListener;

}